package com.gexada.simplechat.config;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import redis.embedded.RedisExecProvider;
import redis.embedded.RedisServer;

/**
 * {@link RedisServer} 只能在启动的时候传入{@code port} 参数，这在windows环境会产生一个错误，导致无法启动，需要设置
 * {@code maxheap} 参数。继承并重载了构造方法，传入启动参数。
 * 
 * @author Gex
 *
 */
public class ConfiguarableRedisServer extends RedisServer {

	public ConfiguarableRedisServer(Map<String, String> config, Integer port) throws IOException {
		super(port);
		File executable = RedisExecProvider.defaultProvider().get();
		List<String> configStr = new ArrayList<>();
		configStr.add(executable.getAbsolutePath());
		configStr.add("--port");
		configStr.add(Integer.toString(port));
		for (Entry<String, String> en : config.entrySet()) {
			configStr.add("--" + en.getKey());
			configStr.add(en.getValue());
		}
		this.args = configStr;
	}

}
